package com.zjsru.oneDay;

/**
 * 完美数
 * <p>
 * 输入：num = 28
 * 输出：true
 * 解释：28 = 1 + 2 + 4 + 7 + 14
 * 1, 2, 4, 7, 和 14 是 28 的所有正因子。
 */

public class checkPerfectNumber {
    public boolean checkPerfectNumber(int num) {
        if (num == 1) {
            return false;
        }
        int sum = 1;
        for (int i = 2; i * i < num; i++) {
            if (num % i == 0) {
                sum += i;
                if (i * i < num) {
                    sum += num / i;
                }
            }
        }
        return sum == num;
    }

    public static void main(String[] args) {
        checkPerfectNumber checkPerfectNumber = new checkPerfectNumber();
        int num = 28;
        System.out.println(checkPerfectNumber.checkPerfectNumber(num));
    }
}
